<%-- 
    Document   : daadd
    Created on : 2024年3月31日, 上午9:24:50
    Author     : JUST
--%>
<%@page import="cn.edu.just.secondwebapp.serviceimpl.PersonServiceImpl"%>
<%@page import="cn.edu.just.secondwebapp.service.PersonService"%>
<%@page import="cn.edu.just.secondwebapp.dao.PersonDao"%>
<%@page import="cn.edu.just.secondwebapp.daoimpl.PersonDaoImpl"%>
<%@page import="cn.edu.just.secondwebapp.util.DatabaseConnectionUtil"%>
<%@page import="java.math.BigDecimal"%>
<%@page import="java.util.Date"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="cn.edu.just.secondwebapp.entity.Person"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <%
            String msg;
            request.setCharacterEncoding("utf-8");
            String name = request.getParameter("name");
            String age = request.getParameter("age");
            Integer ageInt =  Integer.parseInt(age);
            
            String birthday = request.getParameter("birthday");
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Date birthdayDate = sdf.parse(birthday);
            
            String salary = request.getParameter("gongzi");
            BigDecimal sal = new BigDecimal(salary);            
            Person p = new Person(null,name,ageInt,birthdayDate,sal);
            DatabaseConnectionUtil dcu = new DatabaseConnectionUtil();
            PersonDao personDao = new PersonDaoImpl(dcu.getConnection());
            PersonService personService = new PersonServiceImpl(personDao);
            boolean success = personService.addPerson(p);    
           
            if(success){
                msg = "插入成功";
            }else{
                msg = "插入失败";
            } 
            
            //response.setHeader("refresh", "5;URL=ShowAllPersons.jsp");
        %>
    </head>
    <body>
        
        <h1><%= msg%>！！</h1>
    </body>
</html>
